package com.domain.service.impl;

import com.domain.common.Result;
import com.domain.dao.CommentMapper;
import com.domain.dao.PublishAcceptanceMapper;
import com.domain.service.PublishAcceptanceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@Service
@Transactional(rollbackFor = Exception.class)
public class PublishAcceptanceServiceImpl implements PublishAcceptanceService {

    @Autowired
    private PublishAcceptanceMapper publishAcceptanceMapper;
    @Autowired
    private CommentMapper commentMapper;

    /**
     * 获取我的帮忙列表
     *
     * @param userId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    public Result getUsersPublishAcceptanceList(String userId, String pageNum, String pageSize) {
        PageHelper.startPage(new Integer(pageNum), new Integer(pageSize));
        List<Map<String, Object>> lists = publishAcceptanceMapper.selectByUserId(userId);
        for (Map<String, Object> b : lists) {
            b.put("commentsSize", commentMapper.selectBypublishId(b.get("pId").toString()).size());
            b.put("itisRedPackge", b.get("itisRedPackge").toString());
        }
        PageInfo pageResult = new PageInfo(lists);
        return Result.success("操作成功", pageResult.getList());
    }
}
